from jinja2 import Environment, FileSystemLoader
from zhipuai import ZhipuAI

#promt存放目录
PROMPT_DIR = "prompt/"

#声明环境
PROMPT_ENV = Environment(loader=FileSystemLoader(PROMPT_DIR))

#加载模板
NEWS_TEMP = PROMPT_ENV.get_template('summary.md')

with open('../data/news.txt') as f:
    news_list = f.readlines()


API_KEY = ""

CHAT_MODEL = 'glm-4-air'

client = ZhipuAI(api_key=API_KEY)
prompt = NEWS_TEMP.render(news_list=news_list)

try:
    response =  client.chat.completions.create(
        model="glm-4-plus",
        messages=[
            {
                "role": "user",
                "content": prompt
            }
        ]
    )
except Exception as e:
    print(e)
print(response)
print(response.choices[0].message.content)